#include <iostream>
#include <deque>
#include <climits>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    int *sum = new int[n + 5];
    for (int i = 1; i <= n; ++i) {
        cin >> sum[i];
        sum[i] += sum[i - 1];
    }

    int ans = INT_MIN;
    deque<int> q(0);
    for (int i = 1; i <= n; ++i) {
        if (i - q.front() > m) q.pop_front();
        ans = max(ans, sum[i] - sum[q.front()]);
        while (!q.empty() && sum[q.back()] > sum[i]) q.pop_back();
        q.push_back(i);
    }
    cout << ans << endl;

    delete [] sum;
    return 0;
}
